Array.from(arrayLike[, mapFunction[, thisArg]])

const someNumbers = { '0': 10, '1': 15, length: 2 };

Array.from(someNumbers, value => value * 2); // => [20, 30]


//1、将类数组对象转换为真正数组：
let arrayLike = {
    0: 'tom', 
    1: '65',
    2: '男',
    3: ['jane','john','Mary'],
    'length': 4
}
let arr = Array.from(arrayLike)
console.log(arr) // ['tom','65','男',['jane','john','Mary']]

//2.克隆数组
const numbers = [3, 6, 9];
const numbersCopy = Array.from(numbers);

numbers === numbersCopy; // => false

//3. 使用值填充数组
const length = 3;
const init   = 5;
const result = Array.from({ length }, () => init);

result; // => [5, 5, 5]

//　Array.from还可以接受第二个参数，作用类似于数组的map方法，用来对每个元素进行处理，将处理后的值放入返回的数组。如下
let arr = [12,45,97,9797,564,134,45642]
let set = new Set(arr)
Array.from(set, item => item + 1) // [ 13, 46, 98, 9798, 565, 135, 45643 ]	


const length = 3;
const init   = 1;
const result = Array(length).fill(init);

result; // => [1, 1, 1]

//3.2 使用对象填充数组
const length = 3;
const resultA = Array.from({ length }, () => ({}));
const resultB = Array(length).fill({});

resultA; // => [{}, {}, {}]
resultB; // => [{}, {}, {}]

resultA[0] === resultA[1]; // => false
resultB[0] === resultB[1]; // => true

//4. 生成数字范围
function range(end) {
	return Array.from({length:end},(_, index) => index);
}
range(4); // => [0, 1, 2, 3]

//5.数组去重
function unique(array) {
  return Array.from(new Set(array));
}

unique([1, 1, 2, 3, 3]); // => [1, 2, 3]

//6.将Set结构的数据转换为真正的数组：　 
let arr = [12,45,97,9797,564,134,45642]
let set = new Set(arr)
Array.from(set) // [ 12, 45, 97, 9797, 564, 134, 45642 ]